package com.JL.engine.components;

import java.awt.*;
import java.awt.geom.Point2D;
import com.JL.engine.model.Component;

public class PositionComponent extends Component {
    private final Point2D position = new Point2D.Double();


    public Point2D getPosition(){
        return new Point2D.Double(getX(), getY());
    }
    /*获得横坐标
    * 返回值*/
    public double getX(){ return position.getX();}
    /*获得纵坐标
     * 返回值*/

    public double getY(){ return position.getY();}
    /*设置位置
    * 形参：x - 横坐标
    *      y - 纵坐标 */

    public void setPosition( double x, double y){
        position.setLocation(x,y);
    }
    /*设置基于当前的横坐标的偏移量
    * 形参：x-横坐标*/
    public void setTranslationX(double x){
        setPosition(x,0);
    }
    /*设置基于当前的纵坐标的偏移量
    * 形参：y-纵坐标*/
    public void setTranslationY(double y){
        setPosition(0,y);
    }
    /*设置基于当前的横坐标和纵坐标的偏移量
    * 形参：x-横坐标
    *      y-纵坐标*/
    public void setTranslation(double x,double y){
        position.setLocation(position.getX()+x,position.getY()+y);
    }
    /*
    设置基于当前的横坐标和纵坐标的偏移量
    translation 偏移量信息
     */
    public void setTranslation(Point2D translation){
        position.setLocation(position.getX()+translation.getX(),position.getY()+translation.getY());
    }
   /*设置位置
   * 形参：position - 位置信息*/
    public void setPosition(Point2D position){
        setPosition(position.getX(),position.getY());
    }
}
